package com.xywy.find;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.widget.TitleBar2;

/*****************************************
 * @ClassName: JbzcActivity
 * @Package com.xywy.find
 * @Description: 修改，增加进度条
 * @author CodeMonkeyCui
 * @date 2014年11月21日 下午2:48:29
 * @version V1.0
 *******************************************/
public class JbzcActivity extends BaseActivity {
	private static final String TAG = "JbzcActivity";
	private WebView webView;
	private ProgressBar progressBar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置为全屏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.find_jbzc_index);

		initView();

	}

	@Override
	public void initView() {
		// title
		TitleBar2 titleBar = (TitleBar2) findViewById(R.id.find_jbzc_title_bar);
		TextView tvTitle = titleBar.getTitle();
		TextView tvBack = titleBar.getTvBack();
		titleBar.getGo().setVisibility(View.INVISIBLE);
		titleBar.onClickBack(this);
		tvTitle.setText(getString(R.string.find_3));
		tvBack.setText(getString(R.string.main_tab_tv_find));
		progressBar = (ProgressBar) findViewById(R.id.find_jbzc_progressBar);
		webView = (WebView) findViewById(R.id.wv_find_jbzc);

		// 通过WebChromeClient可以处理JS对话框，titles, 进度，等 ，这个例子，我们处理
		// ，我们将websit下载的进度同步到acitity的进度条上。
		webView.getSettings().setJavaScriptEnabled(true); // 设置支持Javascript
		webView.getSettings().setBuiltInZoomControls(true); // 页面添加缩放按钮
		webView.requestFocus(); // 触摸焦点起作用.如果不设置，则在点击网页文本输入框时，不能弹出软键盘及不响应其他的一些事件。
		webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // 取消滚动条
		
		// 设置在app中打开，而不是在浏览器中
		webView.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
				progressBar.setVisibility(View.GONE);

			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				// TODO Auto-generated method stub
				super.onPageStarted(view, url, favicon);
				progressBar.setVisibility(View.VISIBLE);
				progressBar.setProgress(1);
			}

		});
		webView.setWebChromeClient(new WebChromeClient() {

			@Override
			public boolean onJsAlert(WebView view, String url, String message,
					JsResult result) {
				// TODO Auto-generated method stub
				return super.onJsAlert(view, url, message, result);
			}

			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				// TODO Auto-generated method stub
				super.onProgressChanged(view, newProgress);
				progressBar.setProgress(newProgress);
			}
		});
		webView.loadUrl(getString(R.string.find_webview_jbzc));
//		progressBar = new ProgressBar(this, null,
//				android.R.attr.progressBarStyleHorizontal);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
			webView.goBack();
			return true;

		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

	@Override
	public void preInit() {

	}

	@Override
	public void loadData() {

	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Stattistics();
	}
	
	/**
	 * 友盟统计收藏 帮助
	 */
	public void Stattistics(){
	MobclickAgent.onEvent(this, "Jbzc_001");
	}
	
}
